package cn.sciento.farm.devicemanager.gateway.model.downlink;

import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

import static cn.sciento.farm.devicemanager.common.constant.MqttConstant.*;

/**
 * @author Walton
 * @since 2020/8/24 9:49
 */
@Data
public class InsectLampConfigData extends AbstractBlockData {

    private Integer modbusAddr;

    private Long id;
    private String eui;

    private Integer linghtControlTime;

    private String startControlTime;

    private String endControlTime;

    private Integer collectTime;

    private Integer heatTimeSet;

    private Double heatTemperatureSet;

    private Integer dataPeriod;

    private Integer phtotsPeriod;

    private Integer ratio;

    private Integer paramRefresh;

    @Override
    public String generateId() {
        return String.format(ISM_CONTROL_PARAM_BLOCK_ID,eui);
    }

    @Override
    public String generateStatus() {
        return null;
    }

    @Override
    public MqttContent generate() {
        Map<String,Object> map = new HashMap<>();
        map.put("id", modbusAddr);
        map.put("linghtCT", linghtControlTime);
        map.put("startCT", startControlTime);
        map.put("endCT", endControlTime);
        map.put("collectT", collectTime);
        map.put("hTimeSet", heatTimeSet);
        map.put("hTempSet", heatTemperatureSet);
        map.put("dataPeriod", dataPeriod);
        map.put("phtotsPeriod", phtotsPeriod);
        map.put("ratio", ratio);
        map.put("paramRefresh", paramRefresh);
        String payload = JSON.toJSONString(map);
        String topic = String.format(ISM_CONTROL_TOPIC, eui);
        return new MqttContent(topic,payload);
    }
}
